package com.bxd.baodan.adapter;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bxd.baodan.App;
import com.bxd.baodan.R;
import com.bxd.baodan.activity.WebViewPager;
import com.bxd.baodan.item.ProductItem;
import com.umeng.analytics.MobclickAgent;

/**
 * Created by Administrator on 2017/6/26.
 */

public class ProductItemAction {
    public static void action(final Context ct, ViewHolder holder, final ProductItem item ) {


        holder.setText(R.id.p_name, item.p_name);
        holder.setText(R.id.p_features, item.p_features);
        Glide.with(ct).load(item.p_img).
                error(R.drawable.img_error).
                into(((ImageView) holder.getView(R.id.p_image)));



        holder.getView(R.id.p_view).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                try {

                    Intent intent = new Intent(App.getContext(), WebViewPager.class);

                        intent.putExtra("startUrl", item.p_url);

                    intent.putExtra("p_id", item.p_id);
                    ct.startActivity(intent);
                    if (ct != null) {

                        ((Activity)ct).overridePendingTransition(R.anim.slide_in_right,
                                R.anim.slide_out_left);
                    }

                } catch (Exception e) {
                    // TODO: handle exception
                }



            }
        });


    }

    public static void action(final Context ct, ViewHolder holder, final ProductItem item , final String from) {

        holder.setText(R.id.p_name, item.p_name);
        holder.setText(R.id.p_features, item.p_features);
        Glide.with(ct).load(item.p_img).
                error(R.drawable.img_error).
                into(((ImageView) holder.getView(R.id.p_image)));



        holder.getView(R.id.p_is_main).setVisibility(item.p_is_main.equals("0") ? View.GONE : View.VISIBLE);
        holder.getView(R.id.p_is_hot).setVisibility(item.p_is_hot.equals("0") ? View.GONE : View.VISIBLE);
        holder.getView(R.id.p_is_new).setVisibility(item.p_is_new.equals("0") ? View.GONE : View.VISIBLE);

        holder.getView(R.id.p_view).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (from.equals("all_produce")) {
                    MobclickAgent.onEvent(App.getContext(), "v5_5_1_SY_zcp_cp");
                }

                try {

                    // item.p_url ="http://rest-bxd.xtest.tech/html/product/detail?p_id=37";
                    MobclickAgent.onEvent(App.getContext(), "v5_5_1_SY_zcp_cp");


                    Intent intent = new Intent(App.getContext(), WebViewPager.class);

                        intent.putExtra("startUrl", item.p_url);

                    intent.putExtra("p_id", item.p_id);
                    ct.startActivity(intent);
                    if (ct != null) {

                        ((Activity)ct).overridePendingTransition(R.anim.slide_in_right,
                                R.anim.slide_out_left);
                    }

                } catch (Exception e) {
                    // TODO: handle exception
                }



            }
        });


    }
}
